<?php
/* *
 * $Author ：PHPYUN开发团队
 *
 * 官网: http://www.phpyun.com
 *
 * 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
 *
 * 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class apply_employe_controller extends company{
	function index_action(){
	
		include(CONFIG_PATH."db.data.php");
		
		$company=$this->get_user();
		
		$save=$this->obj->DB_select_once("lssave","`uid`='".$this->uid."'and `savetype`='4'");
		$save=unserialize($save['save']);
		if($save['lastupdate']){
			$save['time']=date('H:i',ceil(($save['lastupdate'])));
		}
		$this->yunset("save",$save);
		$CacheArr=$this->MODEL('cache')->GetCache(array('hy','job','city','com','circle'));
		$this->yunset($CacheArr);
		/*jam获取该企业下申请认证的员工*/
		$where = ' and 1';
		if($_GET['w']){
			$where = ' and  status = "'.$_GET['w'].'" ';
		}
		$applys = $this->obj->DB_select_all("company_user","`companyid`='".$this->uid."' " . $where);
		foreach ($applys as $key => $value) {
			$applys[$key]['userinfo'] = $this->obj->DB_select_once("member","`uid`='".$value['uid']."' ",'realname_jam,mobile_jam');
			if($value['status'] == 1){
				$applys[$key]['status_name']  = '等待审核';
			}elseif($value['status'] == 2){
				$applys[$key]['status_name']  = '通过';
			}elseif($value['status'] == 3){
				$applys[$key]['status_name']  = '拒绝';
			}
		}
		// print_r($applys);die("b");
		$this->yunset("applys",$applys);
		
		$this->yunset("today",date('Y-m-d',time()));
		$this->yunset("js_def",8);
        $this->public_action();
		$this->com_tpl('applylist');
	}
	/*允许通过*/
	function allow_action(){
		$applyinfo = $this->obj->DB_select_once("company_user","`id`='".$_POST['id']."' ",'uid');
		if($_POST['type'] == 'allow' && !empty($_POST['id'])){
			include(CONFIG_PATH."db.data.php");
			/*jam允许通过*/
			$nid=$this->obj->update_once("company_user",array('status'=>2),array('companyid'=>$this->uid,'id'=>$_POST['id']));
			

			if($nid){
				$this->automsg("您的员工认证申请已通过",$applyinfo['uid']);
				echo 6;die();
			}else{
				echo 4;die();
			}
		}else if($_POST['type'] == 'allownot' && !empty($_POST['id'])){
			/*jam拒绝*/
			$nid=$this->obj->update_once("company_user",array('status'=>3),array('companyid'=>$this->uid,'id'=>$_POST['id']));
			if($nid){
				$this->automsg("您的员工认证申请被拒绝，您可以重新申请",$applyinfo['uid']);
				echo 6;die();
			}else{
				echo 4;die();
			}
		}
	}
	function edit_action(){
		die("g");
		include(CONFIG_PATH."db.data.php");
		$this->yunset("arr_data",$arr_data);
		$statics = $this->company_satic();
		if($_GET['id']){
			$id=(int)$_GET['id'];
		}else{
			if($_GET['jobcopy']){
				if( $statics['addjobnum'] == 2){
					if(intval($statics['integral']) < intval($this->config['integral_job'])){
						$this->ACT_msg($_SERVER['HTTP_REFERER'],"你的".$this->config['integral_pricename']."不够发布职位！",8);
					}
				}
			}
			$id=(int)$_GET['jobcopy'];
		}
		$row=$this->obj->DB_select_once("company_job","`id`='".$id."' and `uid`='".$this->uid."'");
		if($row==''){
			$this->ACT_msg("index.php?c=jobadd","职位参数错误！");
		}
		$lang[] = @explode(',',$row['lang']);
		//whp  新增职位标签 s  0318
		$label[] = @explode(',',$row['label']);
		if($label){
			foreach($label as $key=>$val){
				$row['label']=$val;
			}
		}
		//whp  新增职位标签 e  0318
		if($lang){
			foreach($lang as $key=>$val){
				$row['lang']=$val;
			}
		}


	 
		$company=$this->get_user();
		if($company['linktel']==''&&$company['linkphone']){
			$company['linktel']=$company['linkphone'];
		}
		 
		
		$this->yunset($this->MODEL('cache')->GetCache(array('hy','job','city','com','user')));
		if($row['autotime']>time()){
			$row['autodate']=date("Y-m-d",$row['autotime']);
		}
		$job_link=$this->obj->DB_select_once("company_job_link","`jobid`='".$id."' and `uid`='".$this->uid."'");
		$this->yunset("job_link",$job_link);
		$row['islink']=$job_link['link_type'];
 		$row['isemail']=$job_link['email_type'];
 		$row['description']=str_replace(array("ti<x>tle","“","”"),array("title"," "," "),$row['description']);
		$this->public_action();
		$this->yunset("statis",$statics);
		$this->yunset("company",$company);
		$this->yunset("row",$row);
		$this->yunset("js_def",3);
		$this->com_tpl('jobadd');
	}
	function save_action(){	
		if($_POST['submitBtn']){
			$id=intval($_POST['id']);
			if($id){
				$row=$this->obj->DB_select_once("employe","`id`='".$id."' ");
			}
			$this->cookie->SetCookie("delay", "", time() - 60);
			$state= intval($_POST['state']);
			unset($_POST['submitBtn']);
			unset($_POST['id']);
			unset($_POST['state']);
			
			$comjob=$this->obj->DB_select_all("employe","`id`='".$id."' ","`id`");
			
			if($comjob['id']!=$id && $id && $comjob['id']){
				$this->ACT_layer_msg("员工名称已存在！",8);
			}
			$companycert=$this->obj->DB_select_once("employe","`id`='".$id."' ","id");
				
			$CacheList=$this->MODEL('cache')->GetCache(array('com'));

			$company=$this->get_user();
			$logid = $_POST['logid'];
			unset($_POST['logid']);
			unset($_POST['jobcopy']);
			unset($_POST['save']);
			if(!$id||intval($_POST['jobcopy'])==$id){
				
				$_POST['company_id'] = $company['uid'];
				$_POST['add_time'] = time();
				// echo "<pre>";print_r($_POST);die("a");
 				$nid=$this->obj->insert_into("employe",$_POST);
				$name="添加员工";
				$type='1';
				if($nid){

					$state_content = "添加了新员工 <a href=\"".$this->config['sy_weburl']."/index.php?m=employe&c=employeadd&id=$nid\" target=\"_blank\">".$_POST['employe_name']."</a>。";
					$this->addstate($state_content,2);
					$Warning=$this->MODEL("warning");
					$Warning->warning("1");
				}
			}else{
				
				$where['id']=$id;
				// echo "<pre>";print_r($_POST);die("b");
				$nid=$this->obj->update_once("employe",$_POST,$where);
				$name="更新员工";
				$type='2';
			}
			if($nid){
				
				$this->obj->member_log($name."《".$_POST['employe_name']."》",1,$type);
				$this->obj->DB_update_all("user_log","`status`='1'","`id`='".$logid."'");
				if($id==''){
					$this->ACT_layer_msg($name."成功！",9,$nid);
				}else{
					$this->ACT_layer_msg($name."成功！",9,$id);
				}
			}else{
 				$this->obj->DB_update_all("user_log","`status`='2'","`id`='".$logid."'");
				$this->ACT_layer_msg($name."失败！",8,$_SERVER['HTTP_REFERER']);
			}
			
		}
	}
	function del_action(){
		if($_GET['del']||$_GET['id']){
			if(is_array($_GET['del'])){
				$del=@implode(",",$_GET['del']);
				$layer_type=1;
			}else{
				$del=(int)$_GET['id'];
				$layer_type=0;
			}
		}
		$oid=$this->obj->DB_delete_all("employe","`id` in (".$del.") and `company_id`='".$this->uid."'","");
		if($oid){
			$this->obj->member_log("删除员工",9,3);
			$this->layer_msg('删除成功！',9,$layer_type,$_SERVER['HTTP_REFERER']);
		}else{
			$this->layer_msg('删除失败！',8,$layer_type,$_SERVER['HTTP_REFERER']);
		}
	}
	function getJobNum_action(){
		if($_POST['uid']){
			$statis = $this->company_satic();
			if($statis){
				echo $statis['addjobnum'];die;
			}
		}
	}
}
?>